from itsdangerous import TimedJSONWebSignatureSerializer,BadData,SignatureExpired
from django.conf import settings

def generate_access_token(openid):
    serializer = TimedJSONWebSignatureSerializer(
        secret_key=settings.SECRET_KEY,
        expires_in=3600
    )
    token = serializer.dumps({
        'openid':openid
    })
    return token.decode()
def check_access_token(token):
    serializer = TimedJSONWebSignatureSerializer(
        secret_key=settings.SECRET_KEY
    )
    try:
        payload = serializer.loads(token)
    except Exception as e:
        print(e)
        return None
    return payload.get('openid')
